package com.roadjava.javaweb.student.service.impl;

import com.roadjava.javaweb.student.beans.entity.ScoreDO;
import com.roadjava.javaweb.student.beans.req.StudentRequest;
import com.roadjava.javaweb.student.beans.res.ResultDTO;
import com.roadjava.javaweb.student.beans.res.TableResult;
import com.roadjava.javaweb.student.beans.vo.ScoreVO;
import com.roadjava.javaweb.student.beans.vo.StudentVO;
import com.roadjava.javaweb.student.dao.ScoreDao;
import com.roadjava.javaweb.student.dao.impl.ScoreDaoImpl;
import com.roadjava.javaweb.student.service.ScoreService;


public class ScoreServiceImpl implements ScoreService {
    private ScoreDao scoreDao = new ScoreDaoImpl();
    @Override
    public boolean addScore(ScoreDO scoreDO) {
        return scoreDao.addScore(scoreDO) == 1;
    }

    @Override
    public ResultDTO<TableResult<ScoreVO>> queryScoreByPage(StudentRequest studentRequest) {
        TableResult<ScoreVO> tableResult = scoreDao.queryScoreByPage(studentRequest);
        tableResult.setPageNow(studentRequest.getPageNow());
        tableResult.setStudentName(studentRequest.getStudentName() == null ? "" : studentRequest.getStudentName());
        ResultDTO<TableResult<ScoreVO>> resultDTO = ResultDTO.buildSuccess(tableResult);
        return resultDTO;
    }

    @Override
    public ResultDTO<ScoreVO> getScoreById(long scoreId) {
        ScoreVO scoreVO = scoreDao.getScoreById(scoreId);
        ResultDTO<ScoreVO> resultDTO = ResultDTO.buildSuccess(scoreVO);
        return resultDTO;
    }

    @Override
    public boolean updateScore(ScoreDO scoreDO) {
        return scoreDao.updateScore(scoreDO) == 1;
    }

    @Override
    public boolean deleteScoreById(long scoreId) {
        return scoreDao.deleteScoreById(scoreId) == 1;
    }
}
